package com.yjjxt

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

import scala.collection.mutable.ListBuffer

object Hello10MapPartition {
  def main(args: Array[String]): Unit = {
    val sparkContext = new SparkContext((new SparkConf().setMaster("local").setAppName("Join" + System.currentTimeMillis())))
    val array1 = Array[String]("Hello1 user1", "Hello2 user1", "Hello user11", "Hello user12", "user1 apple1", "user orange")
    val array2 = Array[String]("Hello1 user2", "Hello2 user2", "Hello user21", "Hello user22", "user2 apple2", "user orange")
    val lines1 = sparkContext.parallelize(array1, 7)
    val lines2 = sparkContext.parallelize(array2, 4)

    val lines11: RDD[String] = lines1.mapPartitions(iter => {
      val list = ListBuffer[String]()
      while (iter.hasNext) {
        list.+=("yjx:" + iter.next())
      }
      list.iterator
    })
    lines11.foreach(println)

    //    lines2.mapPartitions(iter => {
    //      println("lines2迭代器对象=》" + iter)
    //      while (iter.hasNext) {
    //        println(iter.next())
    //      }
    //      iter
    //    }).count()
  }

}
